package reflection;

/**
 * @Author Stringzhua
 * @Date 2024/11/5 10:14
 * description:
 */
public class Demo01 {
    public static void main(String[] args) throws ClassNotFoundException {
        //获取Class对象的三种方式
        Class class1 = Class.forName("reflection.Student");
        Class class2 = Student.class;
        Class class3 = new Student().getClass();


        //说明类不会被重复加载,三个class对象的哈希值相同
        System.out.println(class1.hashCode());//1163157884
        System.out.println(class2.hashCode());//1163157884
        System.out.println(class3.hashCode());//1163157884

        //获取当前的类型信息
        System.out.println("完全限定名" + class1.getName());
        System.out.println("简单类名" + class1.getSimpleName());
        System.out.println("所在包名" + class1.getPackage().getName());
    }
}

class Student {
    private String stuName;

    //构造方法
    public Student() {
        System.out.println("这是无参构造方法");
    }

    public Student(String stuName) {
        System.out.println("这是有参构造方法");
        this.stuName = stuName;
    }

    public void push() {
        System.out.println("这是普通方法");
    }
}
